package com.lenovo.leos.filebrowser.engine.model;

import java.io.IOException;
import java.io.UnsupportedEncodingException;

import android.content.Context;

import com.lenovo.leos.filebrowser.engine.util.Log;

public class FileComparatorBySize extends FileComparator {
	private static final String TAG = "FileComparatorBySize";
	
	public FileComparatorBySize(Context context) throws IOException {
		super(context);
	}

	//@Override
	public int compare(IconifiedText object1, IconifiedText object2) {
		// TODO Auto-generated method stub
		long size1 = object1.getSize();
		long size2 = object2.getSize();
		if (size1 != size2)
			return size1 > size2 ? -1 : 1;
		/** descend is default order */
		else {
			String name1 = object1.getFile().getName();
			String name2 = object2.getFile().getName();
			try {
				return compareString(name1, name2);
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				Log.e(TAG,
						"UnsupportedEncodingException in FileComparatorBySize");
				e.printStackTrace();
			}
		}
		return 1;
	}
}